package io.netty.handler.ssl;

import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException;

import javax.crypto.NoSuchPaddingException;

/**
 * SSL 工具类
 * 
 * @author 618lf
 */
public class NettySslKit {

	/**
	 * 加载 X509Certificate
	 * 
	 * @param in
	 * @return
	 * @throws CertificateException
	 */
	public static X509Certificate[] toX509Certificates(InputStream in) throws CertificateException {
		return SslContext.toX509Certificates(in);
	}

	/**
	 * 加载 PrivateKey
	 * 
	 * @param in
	 * @param keyPassword
	 * @return
	 * @throws NoSuchAlgorithmException
	 * @throws NoSuchPaddingException
	 * @throws InvalidKeySpecException
	 * @throws InvalidAlgorithmParameterException
	 * @throws KeyException
	 * @throws IOException
	 */
	public static PrivateKey toPrivateKey(InputStream in, String keyPassword)
			throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException,
			InvalidAlgorithmParameterException, KeyException, IOException {
		return SslContext.toPrivateKey(in, keyPassword);
	}
}
